﻿Imports Entidad
Imports Utilitario

Public Class frmConfirmacionBultos

    Dim contador As Integer = 0

    Sub mensaje(ByVal men As String)
        MsgBox(men, MsgBoxStyle.Information, "Mensajes al Usuario")
    End Sub

    Sub calcular(numero1 As Integer, numero2 As Integer, numero3 As Integer)
        If numero1 < numero2 Then
            txtCantPendiente.Text = CStr(numero1 - numero3)
        Else
            txtCantPendiente.Text = CStr(numero2 - numero3)
        End If

        If CInt(txtCantPendiente.Text) < 0 Then
            txtCantBulto.Text = "0"
        End If
    End Sub

    Sub digitarNumero(letra As String)
        If presiona = True Then
            If txtCantBulto.Text = "0" Then
                txtCantBulto.Text = letra
            Else
                txtCantBulto.Text = txtCantBulto.Text.Trim & letra
            End If
        Else
            If txtNumeros.Text = "0" Then
                txtNumeros.Text = letra
            Else
                txtNumeros.Text = txtNumeros.Text.Trim & letra
            End If
        End If
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub frmConfirmacionBultos_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        lblArticulo.Text = nombreArticuloMuestra
        txtCantBulto.Focus()
        txtRestante.Text = CInt(txtCantidadBulto.Text) - CInt(txtNumeros.Text)
        calcular(CInt(txtCantPedido.Text), CInt(txtCantPickeada.Text), CInt(txtCantBulto.Text.Trim))
        If presiona = True Then
            pnlPedAsig.Visible = True
            pnlBulto.Visible = False
            txtCantBulto.Visible = True
        Else
            pnlPedAsig.Visible = False
            pnlBulto.Visible = True
            txtCantidadBulto.Visible = True
        End If
    End Sub

    Private Sub txtCantBulto_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtCantBulto.TextChanged
        calcular(CInt(txtCantPedido.Text), CInt(txtCantPickeada.Text), CInt(txtCantBulto.Text.Trim))
    End Sub

    Private Sub btn1_Click(sender As System.Object, e As System.EventArgs) Handles btn1.Click
        digitarNumero("1")
    End Sub

    Private Sub btn2_Click(sender As System.Object, e As System.EventArgs) Handles btn2.Click
        digitarNumero("2")
    End Sub

    Private Sub btn3_Click(sender As System.Object, e As System.EventArgs) Handles btn3.Click
        digitarNumero("3")
    End Sub

    Private Sub btn4_Click(sender As System.Object, e As System.EventArgs) Handles btn4.Click
        digitarNumero("4")
    End Sub

    Private Sub btn5_Click(sender As System.Object, e As System.EventArgs) Handles btn5.Click
        digitarNumero("5")
    End Sub

    Private Sub btn6_Click(sender As System.Object, e As System.EventArgs) Handles btn6.Click
        digitarNumero("6")
    End Sub

    Private Sub btn7_Click(sender As System.Object, e As System.EventArgs) Handles btn7.Click
        digitarNumero("7")
    End Sub

    Private Sub btn8_Click(sender As System.Object, e As System.EventArgs) Handles btn8.Click
        digitarNumero("8")
    End Sub

    Private Sub btn9_Click(sender As System.Object, e As System.EventArgs) Handles btn9.Click
        digitarNumero("9")
    End Sub

    Private Sub btnPunto_Click(sender As System.Object, e As System.EventArgs) Handles btnPunto.Click
        digitarNumero(".")
    End Sub

    Private Sub btn0_Click(sender As System.Object, e As System.EventArgs) Handles btn0.Click
        digitarNumero("0")
    End Sub

    Private Sub btnConfirmar_Click(sender As System.Object, e As System.EventArgs) Handles btnConfirmar.Click
        If presiona = True Then
            If txtCantBulto.Text <> "0" Then
                cantidad = txtCantBulto.Text.Trim
                DialogResult = Windows.Forms.DialogResult.OK
            Else
                mensaje("Cantidad ingresada es incorrecta.")
                DialogResult = Windows.Forms.DialogResult.No
            End If
        Else
            If txtNumeros.Text <> "0" Then
                cantidad = txtNumeros.Text.Trim
                DialogResult = Windows.Forms.DialogResult.OK
            Else
                mensaje("Cantidad ingresada es incorrecta.")
                DialogResult = Windows.Forms.DialogResult.No
            End If
        End If
    End Sub

    Private Sub txtNumeros_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtNumeros.TextChanged
        txtRestante.Text = CInt(txtCantidadBulto.Text.Trim) - CInt(txtNumeros.Text.Trim)
        If CInt(txtRestante.Text.Trim) < 0 Then
            txtNumeros.Text = "0"
        End If
    End Sub

End Class